/*
* (C) Copyright 2013 Philip Kirchhoff 
* 
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
*-------------------------------------------------------------------------------
* This file is part of the DataLogger library by Philip Kirchhoff
* https://code.google.com/p/pk-data-logger/
* SVN: http://pk-data-logger.googlecode.com/svn/trunk
*-------------------------------------------------------------------------------
* Module    : DlLongChannel.h   
* Author    : Kirchhoff, Philip
* Date      : 01.04.2013
*-------------------------------------------------------------------------------
* Header file for DlLongChannel class
*   
*-------------------------------------------------------------------------------
* Change History:
* 01.04.2013  Kirchhoff 	Created
--------------------------------------------------------------------------------
*/

#ifndef DLLONGCHANNEL_H
#define DLLONGCHANNEL_H

#include "DlDataChannel.h"

/***************************************************************************//**
* @brief DataLogger channel with data type signed long
 ******************************************************************************/
class DlLongChannel : public DlDataChannel
{
public:

    /**************************************************************************//**
    * @brief Constructs an empty analog channel with number, ID and unit
    ******************************************************************************/
    DlLongChannel(unsigned int channelNum,
                  std::string channelId,
                  std::string channelUnit = std::string("-"),
                  std::string channelDescr = std::string("-"));

    /**************************************************************************//**
    * @brief Destructor
    ******************************************************************************/
    ~DlLongChannel();

    /**************************************************************************//**
    * @brief Sets the channels scale factor and offset
    ******************************************************************************/
    void setScale(long offs, double mult)
        {mChannelOffset = offs; mChannelMultiplier = mult;}

    /**************************************************************************//**
    * @brief Sets the channels value range
    ******************************************************************************/
    void setRange(long min, long max);

    /**************************************************************************//**
    * @brief Adds a sample to the channel
    ******************************************************************************/
    void addSample(long &sample);

    /**************************************************************************//**
    * @brief Adds a sample to the channel
    ******************************************************************************/
    void addSample(long *pSample);

    /**************************************************************************//**
    * @brief Adds a sample to the channel
    ******************************************************************************/
    void addSample(void *pSample){addSample((long*)pSample);}

    /**************************************************************************//**
    * @brief Reads a specified sample from the channel
    ******************************************************************************/
    long sample(unsigned int sampleNum);

    /**************************************************************************//**
    * @brief Reads a all samples from the channel
    ******************************************************************************/
    std::vector<long> samples(){return mData;}

    /**************************************************************************//**
    * @brief Gets the number of stored samples
    * @return Number of stored samples
    ******************************************************************************/
    unsigned int numSamples(){return mData.size();}

    /**************************************************************************//**
    * @brief Gets the channel multiplier (scale value)
    * @return Channel multiplier
    ******************************************************************************/
    double channelMultiplier(){return mChannelMultiplier;}

    /**************************************************************************//**
    * @brief Gets the channel offset
    * @return Channel offset
    ******************************************************************************/
    long channelOffset(){return mChannelOffset;}

    /**************************************************************************//**
    * @brief Gets the channel range min value
    * @return Range min value
    ******************************************************************************/
    long channelMin(){return mChannelMin;}

    /**************************************************************************//**
    * @brief Gets the channel range max value
    * @return Range max value
    ******************************************************************************/
    long channelMax(){return mChannelMax;}

    /**************************************************************************//**
    * @brief Get a string-converted sample
    ******************************************************************************/
    std::string sampleString(unsigned int sampleNum);

    /**************************************************************************//**
    * @brief Clear channel data
    ******************************************************************************/
    virtual void clear(){mData.clear();}


private:
    double mChannelMultiplier;
    long mChannelOffset;
    long mChannelMin;
    long mChannelMax;

    std::vector<long> mData;
};
#endif // DLLONGCHANNEL_H
